]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appDisplay: Use LongPress and Click gestures for opening popup menu
authorJonas Dreßler <verdre@v0yd.nl>
Thu, 17 Mar 2022 20:34:52 +0000 (21:34 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 28 Aug 2025 17:14:06 +0000 (19:14 +0200)
We now have ClutterGestures for this, so let's use them instead of listening
to events ourselves.

While at it, remove the custom 600ms long-press duration in favor of Clutters
default 500ms long-press-duration.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2853>

js/ui/appDisplay.js

index 3fa758dcae4715c923f14660c3e0901430cc8422..d109c19b228f2a9069f36c3551cf61ebf0c5056e 100644 (file)
@@ -26,7 +26,6 @@ import * as Main from './main.js';
 
 import * as Config from '../misc/config.js';
 
-const MENU_POPUP_TIMEOUT = 600;
 const POPDOWN_DIALOG_TIMEOUT = 500;
 
 const FOLDER_SUBICON_FRACTION = .4;
@@ -2986,10 +2985,20 @@ export const AppIcon = GObject.registerClass({
         this._menu = null;
         this._menuManager = new PopupMenu.PopupMenuManager(this);
 
-        this._menuTimeoutId = 0;
         this.app.connectObject('notify::state',
             () => this._updateRunningStyle(), this);
         this._updateRunningStyle();
+
+        const longPressGesture = new Clutter.LongPressGesture();
+        longPressGesture.connect('recognize', () => this.popupMenu());
+        this.add_action(longPressGesture);
+
+        const rightClickGesture = new Clutter.ClickGesture({
+            required_button: Clutter.BUTTON_SECONDARY,
+            recognize_on_press: true,
+        });
+        rightClickGesture.connect('recognize', () => this.popupMenu());
+        this.add_action(rightClickGesture);
     }
 
     _onDestroy() {
@@ -2999,14 +3008,11 @@ export const AppIcon = GObject.registerClass({
             GLib.source_remove(this._folderPreviewId);
             this._folderPreviewId = 0;
         }
-
-        this._removeMenuTimeout();
     }
 
     _onDragBegin() {
         if (this._menu)
             this._menu.close(true);
-        this._removeMenuTimeout();
         super._onDragBegin();
     }
 
@@ -3014,13 +3020,6 @@ export const AppIcon = GObject.registerClass({
         return this.app.create_icon_texture(iconSize);
     }
 
-    _removeMenuTimeout() {
-        if (this._menuTimeoutId > 0) {
-            GLib.source_remove(this._menuTimeoutId);
-            this._menuTimeoutId = 0;
-        }
-    }
-
     _updateDotStyle() {
         const themeNode = this._dot.get_theme_node();
         this._dot.translationY = themeNode.get_length('offset-y');
@@ -3033,46 +3032,14 @@ export const AppIcon = GObject.registerClass({
             this._dot.hide();
     }
 
-    _setPopupTimeout() {
-        this._removeMenuTimeout();
-        this._menuTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, MENU_POPUP_TIMEOUT, () => {
-            this._menuTimeoutId = 0;
-            this.popupMenu();
-            return GLib.SOURCE_REMOVE;
-        });
-        GLib.Source.set_name_by_id(this._menuTimeoutId, '[gnome-shell] this.popupMenu');
-    }
-
     vfunc_leave_event(event) {
         const ret = super.vfunc_leave_event(event);
 
         this.fake_release();
-        this._removeMenuTimeout();
-        return ret;
-    }
-
-    vfunc_button_press_event(event) {
-        const ret = super.vfunc_button_press_event(event);
-        const button = event.get_button();
-        if (button === 1) {
-            this._setPopupTimeout();
-        } else if (button === 3) {
-            this.popupMenu();
-            return Clutter.EVENT_STOP;
-        }
-        return ret;
-    }
-
-    vfunc_touch_event(event) {
-        const ret = super.vfunc_touch_event(event);
-        if (event.type() === Clutter.EventType.TOUCH_BEGIN)
-            this._setPopupTimeout();
-
         return ret;
     }
 
     vfunc_clicked(button) {
-        this._removeMenuTimeout();
         this.activate(button);
     }
 
@@ -3087,7 +3054,6 @@ export const AppIcon = GObject.registerClass({
 
     popupMenu() {
         this.setForcedHighlight(true);
-        this._removeMenuTimeout();
         this.fake_release();
 
         if (!this._menu) {
@@ -3228,7 +3194,6 @@ export const AppIcon = GObject.registerClass({
     cancelActions() {
         if (this._menu)
             this._menu.close(true);
-        this._removeMenuTimeout();
         super.cancelActions();
     }
 });